<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>工艺待办生产异常</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
        <input class="layui-input" name="keyword" id="keyword" autocomplete="off" placeholder="请输入编号">
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
</div>
<table class="layui-hide" id="test" lay-filter="test"></table>
<table class="layui-hide" id="testDetial" lay-filter="testDetial"></table>
<div id="formDiv" hidden>
	<form class="layui-form" id="addform">
		<input type="hidden" id="adID" name="adID">
		<input type="hidden" id="adcID" name="adcID"><br>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 100px;">调整过程描述</label>
				<div class="layui-input-inline">
					<textarea lay-verify="revisionDescription" class="layui-textarea" id="revisionDescription" name="revisionDescription" style="width:300px;"></textarea>
				</div><span style="color:red; font-size: 24px;float: left;margin: 40px 0 0 5em;">*</span>
			</div>
			<div class="layui-inline" style="padding-left: 5em;">
				<label class="layui-form-label" style="width: 100px;">调整结果描述</label>
				<div class="layui-input-inline">
					<textarea lay-verify="revisionResult" class="layui-textarea" id="revisionResult" name="revisionResult" style="width:300px;"></textarea>
				</div><span style="color:red; font-size: 24px;float: left;margin: 40px 0 0 5em;">*</span>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 100px;">是否恢复正常</label>
				<div class="layui-input-inline">
					<input lay-filter="isNormal" type="radio" name="isNormal" value="1" title="是"><input lay-filter="isNormal" type="radio" name="isNormal" value="0" title="否" checked>
				</div>
			</div>
			<div class="layui-inline" style="padding-left: 5em;">
				<label class="layui-form-label" style="width: 100px;">是否通过</label>
				<div class="layui-input-inline">
					<input type="radio" name="reserve1" value="0" title="通过" checked><input type="radio" name="reserve1" value="1" title="驳回">
				</div>
			</div>
		</div>
		<div style="display: none;" id="noticeForm">
			<h1 align="center">工艺变更通知单</h1><br>
			<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 100px;">编号</label>
				<div class="layui-input-inline">
					<input class="layui-input" lay-verify="noticeNum" type="text" id="noticeNum" name="noticeNum" style="width:300px;">
				</div><span style="color:red; font-size: 24px;float: right;margin: 10px -5em 0 0;">*</span>
			</div>
			<div class="layui-inline" style="padding-left: 5em;">
				<label class="layui-form-label" style="width: 100px;">日期</label>
				<div class="layui-input-inline">
					<input class="layui-input" lay-verify="noticeDate" type="text" id="noticeDate" name="noticeDate" style="width:300px;">
				</div><span style="color:red; font-size: 24px;float: right;margin: 10px -5em 0 0;">*</span>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label" style="width: 100px;">有效期</label>
				<div class="layui-input-inline">
					<input class="layui-input" lay-verify="validityPeriod" type="text" id="validityPeriod" name="validityPeriod" style="width:300px;">
				</div><span style="color:red; font-size: 24px;float: right;margin: 10px -5em 0 0;">*</span>
			</div>
			<div class="layui-inline" style="padding-left: 5em;">
				<label class="layui-form-label" style="width: 100px;">适用工序</label>
				<div class="layui-input-inline" style="width: 300px;">
					<select class="layui-input" lay-search="" id="applicableProcess" name="applicableProcess" lay-verify="applicableProcess">
						<option value=""></option>
						<c:forEach items="${pList }" var="p">
							<option value="${p.pname }">${p.pname }</option>
						</c:forEach>
					</select>
				</div><span style="color:red; font-size: 24px;float: left;margin: 10px -5em 0 0;">*</span>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label" style="width: 100px;">内容</label>
			<div class="layui-input-inline">
				<textarea class="layui-textarea" lay-verify="content" id="content" name="content" style="width:500px;"></textarea>
			</div><span style="color:red; font-size: 24px;float: left;margin: 40px 0 0 13em;">*</span>
		</div>
		</div>
		<button id="subBtn1" class="layui-btn layui-btn-blue" lay-submit lay-filter="addform" style="margin-left:350px;margin-bottom: 1em;">提交</button>&emsp;&emsp;&emsp;&emsp;<button type="reset" style="margin-bottom: 1em;" class="layui-btn layui-btn-primary">重置</button>
	</form>
</div>
              
          
<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<jsp:include page="ScriptInc.jsp"></jsp:include> 
 
<script>
layui.use(['table','layer','upload','form'], function(){
	var laydate = layui.laydate;
	  
	//执行一个laydate实例
	laydate.render({
		elem: '#noticeDate' //指定元素
	});
	
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form;
	form.on('radio(isNormal)', function(data){
		isNormal = data.value;
		var formDiv = document.getElementById('noticeForm');
		if (data.value == '0'){
			formDiv.style.display = 'none';
			$('#noticeNum').attr("lay-verify", "");
			$('#noticeDate').attr("lay-verify", "");
			$('#validityPeriod').attr("lay-verify", "");
			$('#applicableProcess').attr("lay-verify", "");
			$('#content').attr("lay-verify", "");
			$('#draftPerson').attr("lay-verify", "");
			$('#sign').attr("lay-verify", "");
			$('#approve').attr("lay-verify", "");
		} else if (data.value == '1') {
			formDiv.style.display = '';
			$('#noticeNum').attr("lay-verify", "noticeNum");
			$('#noticeDate').attr("lay-verify", "noticeDate");
			$('#validityPeriod').attr("lay-verify", "validityPeriod");
			$('#applicableProcess').attr("lay-verify", "applicableProcess");
			$('#content').attr("lay-verify", "content");
			$('#draftPerson').attr("lay-verify", "draftPerson");
			$('#sign').attr("lay-verify", "sign");
			$('#approve').attr("lay-verify", "approve");
		}
			   
	     
	});
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				console.log(keyword)
				table.reload('contenttable',{
					method:'get',
					where:{adNum: keyword,
						reserve1: '0'}
					,page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
		}
	
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#test'
	    ,url:'${pageContext.request.contextPath }/abnormalDisposal/listPageAbnormalDisposal.do'
	    ,title: '生产异常处置单数据表'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,where:{reserve1: '0'}
	    ,cols: [[
	      {type: 'checkbox', fixed: 'left'}
	      ,{type: 'numbers', fixed: 'left', title:'序号', width:'5%'}
	      ,{field:'adNum', title:'编号', width:'10%'}
	      ,{field:'processPart', title:'发生的工序段', width:'10%'}
	      ,{field:'adDate', title:'日期', width:'10%', templet: function(d){
	          return timestampToDate(d.adDate.time);
	      }}
	      ,{field:'squadLeader', title:'当班班长', width:'10%'}
	      /* ,{field:'processer', title:'工艺段负责', width:'10%'} */
	      ,{field:'description', title:'异常说明'}
	    ]]
	    ,page: true
	});
	
	//监听行单击事件
	table.on('row(test)', function(obj){
		layer.open({
			  type: 1 		//Page层类型
			  ,area: ['1100px', '70%'] //宽  高
			  ,title: '新增'
			  ,shade: 0.6 	//遮罩透明度
			  ,shadeClose: true //点击遮罩关闭
			  ,maxmin: true //允许全屏最小化
			  ,anim: 1 		//0-6的动画形式，-1不开启
			  ,content: $('#formDiv')
			  ,success: function () {
				  document.getElementById("addform").reset();
				  $('#adID').val(obj.data.adID);
				  var formDiv = document.getElementById('noticeForm');
				  formDiv.style.display = 'none';
				  $('#noticeNum').attr("lay-verify", "");
				  $('#noticeDate').attr("lay-verify", "");
				  $('#validityPeriod').attr("lay-verify", "");
				  $('#applicableProcess').attr("lay-verify", "");
				  $('#content').attr("lay-verify", "");
				  $('#draftPerson').attr("lay-verify", "");
				  $('#sign').attr("lay-verify", "");
				  $('#approve').attr("lay-verify", "");
				  form.render();
			  }
			  ,end: function () {
				  var formDiv = document.getElementById('formDiv');
				  formDiv.style.display = '';
			  }
			});
	});
	
	/**
     * 表单校验
     */
    form.verify({
    	//value：表单的值、item：表单的DOM对象
    	revisionDescription: function(value){
    		if(value == ''){
    			return '调整过程描述不能为空';
    		}
    	},
    	revisionResult: function(value){
    		if(value == ''){
    			return '调整结果描述不能为空';
    		}
    	},
    	craftMan: function(value){
    		if(value == ''){
    			return '不能为空';
    		}
    	},
    	noticeNum: function(value){
    		if(value == ''){
    			return '编号不能为空';
    		}
    	},
    	noticeDate: function(value){
    		if(value == ''){
    			return '日期不能为空';
    		}
    	},
    	validityPeriod: function(value){
    		if(value == ''){
    			return '有效期不能为空';
    		}
    	},
    	applicableProcess: function(value){
    		if(value == ''){
    			return '适用工序不能为空';
    		}
    	},
    	content: function(value){
    		if(value == ''){
    			return '内容不能为空';
    		}
    	},
    	draftPerson: function(value){
    		if(value == ''){
    			return '拟定人不能为空';
    		}
    	},
    	sign: function(value){
    		if(value == ''){
    			return '会签不能为空';
    		}
    	},
    	approve: function(value){
    		if(value == ''){
    			return '标准不能为空';
    		}
    	}
    });
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	$("#subBtn1").attr("disabled",true);
    	$.ajax({
			url : '${pageContext.request.contextPath }/abnormalDisposalCraft/saveAbnormalDisposalCraft.do',
			data : $('#addform').serialize(),
			type : "post",
			dataType : "json",
			}).done(
				function(res) {
					if (res > 0) {
						toastr.success('新增成功！');
						setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
					}
				}
			).fail(
				function(res) {
					layer.close(1);
					toastr.error('新增失败！');
				}
			)
			return false;
    });
});

toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>

</body>
</html>
